package Enum;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-09-20
 * Time: 17:07
 */
public class Test {

    public static void reflectPrivateConstructor() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {

        Class<?> c1 = Class.forName("Enum.TestEnum");


        Constructor<?> constructor = c1.getDeclaredConstructor(String.class,int.class,String.class,int.class);
        constructor.setAccessible(true);

        TestEnum testEnum = (TestEnum)constructor.newInstance("草原绿",9);

        System.out.println(testEnum);

    }

    public static void main(String[] args) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        reflectPrivateConstructor();
    }
    public static void main1(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> c = Class.forName("Enum.TestEnum");
        Constructor<?> constructor = c.getDeclaredConstructor(String.class,int.class);
        constructor.setAccessible(true);
        TestEnum testEnum = (TestEnum)constructor.newInstance("雾霾灰",7);
    }
}
